package cn.edu.sdjzu.xg.eagle.service.impl;

import cn.edu.sdjzu.xg.eagle.entities.File;
import cn.edu.sdjzu.xg.eagle.mapper.FileMapper;
import cn.edu.sdjzu.xg.eagle.service.inface.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Service
public class FileImpl implements FileService {

    @Autowired
    private FileMapper fileMapper;

    @Override
    public String addFile(File file) throws SQLException {
        if (fileMapper.addFile(file)) {
            return "添加文件成功";
        } else {
            return "添加文件失败";
        }
    }

    @Override
    public String deleteFile(int id) throws SQLException {
        if (fileMapper.deleteFile(id)) {
            return "删除文件成功";
        } else {
            return "删除文件失败";
        }
    }

    @Override
    public String updateFile(File file) throws SQLException {
        if (fileMapper.updateFile(file)) {
            return "更新文件成功";
        } else {
            return "更新文件失败";
        }
    }

    @Override
    public File findFileById(int id) throws SQLException {
        return fileMapper.findFileById(id);
    }

    @Override
    public List<File> findFiles() throws SQLException {
        return fileMapper.findFiles(null);
    }

    @Override
    public List<File> findFiles(Map<String, Object> params) throws SQLException {
        return fileMapper.findFiles(params);
    }
}